package com.ant.common.interceptor;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 访问安全过滤器
 */
//@Component
public class AccessSecurityFilter implements Filter {
    static final Logger LOGGER = LoggerFactory.getLogger(AccessSecurityFilter.class);


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletrequest;
        //获取gateway放入的请求头
        String gatewayHeader = request.getHeader("");
        if(StringUtils.isEmpty(gatewayHeader) || !gatewayHeader.equals("")) {
            LOGGER.info("=======无权访问=======");
            return;
        }
        chain.doFilter(servletrequest, servletresponse);
    }

    @Override
    public void destroy() {
    }
}
